-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tempfile V4 #327
Draft
Stebalien
wants to merge
11
commits into
master
Choose a base branch
from
steb/v4-changes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Tempfile V4 #327
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5b4bec6
to
d2993fc
Compare
This was referenced Feb 15, 2025
d85c389
to
1ca5737
Compare
Otherwise it's really easy to pass a temporary file handle by reference, causing it to be dropped by the receiver deleting the underlying file. fixes #115
1. Default to "tmp" as the file prefix instead of ".tmp". 2. Make it possible to construct the builder in a constfn. 3. Use a single lifetime in the builder.
That way, we can pass through additional builder options. This new struct implements AsRef<Path> and Deref<Target=Path> so breakage should be minimal.
To do this, I had to switch from `AsRef<OsStr>` to `&str` for prefixes and suffixes, but a quick search indicates that this will break approximately nothing. I'm sure it'll break _someone's_ code, but there's really no good reason to support arbitrary os-strings here. The benefit is that projects can now construct project-wide temporary file builders, storing them in constants.
1ca5737
to
ba0d77b
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a stack of changes for tempfile v4. My plan is to wait for the next Debian stable release then set the MSRV to that, although I may merge and cut an RC before then. This version tries to be minimally breaking in "normal" code but it will still break some code (ideally code that was already broken/buggy).
Other than the MSRV bump (letting us drop
once_cell
), changes include:AsRef<Path>
on&NamedTempFile
(and friends) instead of directly onNamedTempFile
. That way, functions acceptingAsRef<Path>
won't be able to take (then drop)NamedTempFile
by value. See Got bitten by Drop impl running to early when passing TempDir to fn(p: impl AsRef<Path>) #115..
by default. Temporary files shouldn't generally be hidden. Additionally, it's now possible to configure the default temporary-filename prefix via theenv
package.Builder
can now has a single lifetime instead of separate ones forprefix
andsuffix
. It can also be constructed with a constBuilder::new
if desired.Builder::make
used to take a&Path
but now takes an&MakeParams
struct (that dereferences to a&Path
). This lets us pass additional builder parameters like the desired permissions.TBD:
+t
(sticky)? We can also make it configurable in the builder, the question will be: what's the default behavior?Fixes:
Builder
(orcreate_helper
) to check that the suppliedprefix
andsuffix
don't contain/
#59